import request from '@/utils/request'

const uploadPath = process.env.HOST + '/manage/config/upload.do'
export { uploadPath }

/**
 * 系统配置
 * @type {{systemFonts: (function(): *), getConfig: (function(*=): *), saveConfig: (function(*=): *)}}
 */
export const ConfigService = {
  // 微信相关配置信息
  getWeChatConfig: function(type) { return request({ method: 'get', url: '/manage/config/wechat/list.do', params: { type: type }}) },
  // 系统相关配置信息
  getSysConfig: function(type) { return request({ method: 'get', url: '/manage/config/sys/list.do', params: { type: type }}) },
  // 保存微信配置
  saveWeChatConfig: function(config) { return request({ method: 'post', url: '/manage/config/wechat/save.do', data: config }) },
  // 保存系统配置
  saveSysConfig: function(config) { return request({ method: 'post', url: '/manage/config/sys/save.do', data: config }) },
  // 加载系统字体
  systemFonts: function() { return request({ method: 'get', url: '/manage/config/fonts.do' }) },
  // 生成小程序码
  getWxACode: function() { return request({ method: 'get', url: '/manage/config/generate/acode.do', params: { path: 'pages/index/index' }}) },
  // 生成小程序二维码
  getWxQrCode: function() { return request({ method: 'get', url: '/manage/config/generate/qrcode.do', params: { path: 'pages/index/index' }}) },
  // 加载系统级别的参数
  getSystemParams: function() { return request({ method: 'get', url: '/manage/system/params.do' }) },
  // 加载缓存信息参数
  getCacheParams: function() { return request({ method: 'get', url: '/manage/system/cache.do' }) }
}

/**
 * 系统日志
 * @type {{listSysLog(*): *}}
 */
export const LogsService = {
  // 系统日志
  listSysLog(query) { return request({ method: 'get', url: '/manage/logs/sys.do', params: { ...query }}) },
  // 系统日志
  listUserLog(query) { return request({ method: 'get', url: '/manage/logs/user.do', params: { ...query }}) },
  // 登录日志
  listLoginLog(query) { return request({ method: 'get', url: '/manage/logs/login.do', params: { ...query }}) }
}

/**
 *
 * @type {{deletePlatform: (function(*): *), listPlatform: (function(): *), editPlatform: (function(*=): *), addPlatform: (function(*=): *)}}
 */
export const PlatformService = {
  // 所有平台列表
  listPlatform: function(query) { return request({ method: 'get', url: '/manage/platform/list.do', params: { ...query }}) },
  // 新增平台
  addPlatform: function(data) { return request({ method: 'post', url: '/manage/platform/add.do', data: data }) },
  // 编辑平台
  editPlatform: function(data) { return request({ method: 'post', url: '/manage/platform/edit.do', data: data }) },
  // 编辑平台状态
  editPlatformEnable: function(query) { return request({ method: 'get', url: '/manage/platform/edit/enable.do', params: { ...query }}) },
  // 删除平台
  deletePlatform: function(id) { return request({ method: 'post', url: '/manage/platform/delete.do', data: [id] }) }
}

/**
 *
 * @type {{startTask: (function(*): *), stopTask: (function(*): *), listTask: (function(*): *)}}
 */
export const TaskService = {
  listTask: function(query) { return request({ method: 'get', url: '/manage/tasks/list.do', params: { ...query }}) },
  startTask: function(query) { return request({ method: 'get', url: '/manage/tasks/start.do', params: { ...query }}) },
  stopTask: function(query) { return request({ method: 'get', url: '/manage/tasks/stop.do', params: { ...query }}) }
}
